package reportcs

import (
	"strings"

	"gitee.com/haodreams/golib/autoroute/controller"
	"gorm.io/gorm"
)

// 默认的Json,js 路径
var pathJsJSON = "table/"

// SetJSONJsPath 设置json的默认路径
func SetJSONJsPath(path string) {
	path = strings.ReplaceAll(path, "\\", "/")
	if strings.HasSuffix(path, "/") {
		pathJsJSON = path
	} else {
		pathJsJSON = path + "/"
	}
}

// SetPath 设置json的默认路径
func SetPath(path string) {
	path = strings.ReplaceAll(path, "\\", "/")
	if strings.HasSuffix(path, "/") {
		pathJsJSON = path
	} else {
		pathJsJSON = path + "/"
	}
}

// GetPath 获取配置路径
func GetPath() string {
	return pathJsJSON
}

// TableController 表相关的操作
type TableController struct {
	controller.AuthController
}

var defaultDB *gorm.DB
// SetDefaultDB 设置默认的关系库，必须在程序启动时初始化
func SetDefaultDB(engine *gorm.DB) {
	defaultDB = engine
}

// GetDefaultDB 获取默认的db
func GetDefaultDB() (engine *gorm.DB) {
	return defaultDB
}
